{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {},
      "id": "25fbd0b8-394f-4987-aa3f-fbc4c4dc060f",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -192,
        416
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8d513345-6484-431f-afb7-7cf045c90f4f",
              "name": "Done",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "id": "48e3bd1d-804e-41cf-929d-11f212bf4837",
      "name": "Return",
      "type": "n8n-nodes-base.set",
      "position": [
        1472,
        240
      ],
      "typeVersion": 3.3
    },
    {
      "parameters": {
        "url": "={{ $json.download_url }}",
        "options": {}
      },
      "id": "a412f3be-a0cc-41e5-a839-d2c38577a6dc",
      "name": "Get File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        432,
        112
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "45ce825e-9fa6-430c-8931-9aaf22c42585",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.content }}",
              "rightValue": ""
            },
            {
              "id": "9619a55f-7fb1-4f24-b1a7-7aeb82365806",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            }
          ]
        },
        "options": {}
      },
      "id": "7517a6d0-96c4-4010-b631-9a29d7eb7688",
      "name": "If file too large",
      "type": "n8n-nodes-base.if",
      "position": [
        192,
        128
      ],
      "typeVersion": 2
    },
    {
      "parameters": {},
      "id": "d3da445e-723e-4d32-b07e-7dccd7db149b",
      "name": "Merge Items",
      "type": "n8n-nodes-base.merge",
      "position": [
        192,
        400
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "jsCode": "const orderJsonKeys = (jsonObj) => {\n  const ordered = {};\n  Object.keys(jsonObj).sort().forEach(key => {\n    ordered[key] = jsonObj[key];\n  });\n  return ordered;\n}\n\n// Check if file returned with content\nif (Object.keys($input.all()[0].json).includes(\"content\")) {\n  // Decode base64 content and parse JSON\n  const origWorkflow = JSON.parse(Buffer.from($input.all()[0].json.content, 'base64').toString());\n  const n8nWorkflow = $input.all()[1].json;\n  \n  // Order JSON objects\n  const orderedOriginal = orderJsonKeys(origWorkflow);\n  const orderedActual = orderJsonKeys(n8nWorkflow);\n\n  // Determine difference\n  if (JSON.stringify(orderedOriginal) === JSON.stringify(orderedActual)) {\n    $input.all()[0].json.github_status = \"same\";\n  } else {\n    $input.all()[0].json.github_status = \"different\";\n    $input.all()[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);\n  }\n  $input.all()[0].json.content_decoded = orderedOriginal;\n// No file returned / new workflow\n} else if (Object.keys($input.all()[0].json).includes(\"data\")) {\n  const origWorkflow = JSON.parse($input.all()[0].json.data);\n  const n8nWorkflow = $input.all()[1].json;\n  \n  // Order JSON objects\n  const orderedOriginal = orderJsonKeys(origWorkflow);\n  const orderedActual = orderJsonKeys(n8nWorkflow);\n\n  // Determine difference\n  if (JSON.stringify(orderedOriginal) === JSON.stringify(orderedActual)) {\n    $input.all()[0].json.github_status = \"same\";\n  } else {\n    $input.all()[0].json.github_status = \"different\";\n    $input.all()[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);\n  }\n  $input.all()[0].json.content_decoded = orderedOriginal;\n\n} else {\n  // Order JSON object\n  const n8nWorkflow = $input.all()[1].json;\n  const orderedActual = orderJsonKeys(n8nWorkflow);\n  \n  // Proper formatting\n  $input.all()[0].json.github_status = \"new\";\n  $input.all()[0].json.n8n_data_stringy = JSON.stringify(orderedActual, null, 2);\n}\n\n// Return items\nreturn $input.all();\n"
      },
      "id": "9f21fe3a-30fa-4b1d-a19d-b52d2d72b17d",
      "name": "isDiffOrNew",
      "type": "n8n-nodes-base.code",
      "position": [
        384,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$json.github_status}}",
        "rules": {
          "rules": [
            {
              "value2": "same"
            },
            {
              "value2": "different",
              "output": 1
            },
            {
              "value2": "new",
              "output": 2
            }
          ]
        }
      },
      "id": "68caeeb9-52f3-4517-85f2-f3f1a0c648f6",
      "name": "Check Status",
      "type": "n8n-nodes-base.switch",
      "position": [
        784,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "58d377b6-dbf6-4e35-9f31-4c475e3d026c",
      "name": "Same file - Do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1008,
        240
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "d64db452-6336-4750-b062-69727839e6b5",
      "name": "File is different",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1008,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "0dfdacb2-dad9-4187-982f-af1f81aa0b66",
      "name": "File is new",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1008,
        592
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "resource": "file",
        "owner": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_owner }}"
        },
        "repository": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_name }}"
        },
        "filePath": "={{ $('Config').first().item.repo_path }}{{ $json.subPath }}{{$('Execute Workflow Trigger').first().json.id}}.json",
        "fileContent": "={{$('isDiffOrNew').item.json[\"n8n_data_stringy\"]}}",
        "commitMessage": "={{$('Execute Workflow Trigger').first().json.name}} ({{$json.github_status}})"
      },
      "id": "e3405298-02d3-4fd8-b13f-e7592d145570",
      "name": "Create new file",
      "type": "n8n-nodes-base.github",
      "position": [
        1232,
        592
      ],
      "typeVersion": 1,
      "webhookId": "391aa9f2-336a-4abd-935a-de53611983c2"
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "edit",
        "owner": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_owner }}"
        },
        "repository": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_name }}"
        },
        "filePath": "={{ $('Config').first().item.repo_path }}{{ $json.subPath }}{{$('Execute Workflow Trigger').first().json.id}}.json",
        "fileContent": "={{$('isDiffOrNew').item.json[\"n8n_data_stringy\"]}}",
        "commitMessage": "={{$('Execute Workflow Trigger').first().json.name}} ({{$json.github_status}})"
      },
      "id": "552f5640-97fc-4279-a259-fea20b6876f5",
      "name": "Edit existing file",
      "type": "n8n-nodes-base.github",
      "position": [
        1232,
        400
      ],
      "typeVersion": 1,
      "webhookId": "9f588b70-17a7-4185-bb56-881200c5ca12"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dae43d3b-56e5-4098-b602-862ebf5cd073",
              "name": "subPath",
              "type": "string",
              "value": "={{ $('Execute Workflow Trigger').first().json.createdAt.split('-')[0] }}/{{ $('Execute Workflow Trigger').first().json.createdAt.split('-')[1] }}/"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "be3f0d38-d2e7-46bc-a2a5-d01ce8b1c40e",
      "name": "Create sub path",
      "type": "n8n-nodes-base.set",
      "position": [
        592,
        400
      ],
      "typeVersion": 3.3
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "get",
        "owner": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_owner }}"
        },
        "repository": {
          "__rl": true,
          "mode": "",
          "value": "={{ $('Config').first().item.repo_name }}"
        },
        "filePath": "={{ $('Config').first().item.repo_path }}{{ $('Execute Workflow Trigger').first().json.createdAt.split('-')[0] }}/{{ $('Execute Workflow Trigger').first().json.createdAt.split('-')[1] }}/{{$json.id}}.json",
        "asBinaryProperty": false,
        "additionalParameters": {}
      },
      "id": "deb07340-0c82-4403-b528-e68b3426c9a0",
      "name": "Get file data",
      "type": "n8n-nodes-base.github",
      "position": [
        -16,
        128
      ],
      "typeVersion": 1,
      "alwaysOutputData": true,
      "webhookId": "edc42fd2-7c16-42f5-a4c3-4bb67cd5764f",
      "continueOnFail": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8f6d1741-772f-462a-811f-4c334185e4f0",
              "name": "repo_owner",
              "type": "string",
              "value": "={{ $vars.repo_owner }}"
            },
            {
              "id": "8cac215c-4fd7-422f-9fd2-6b2d1e5e0383",
              "name": "repo_name",
              "type": "string",
              "value": "={{ $vars.repo_name }}"
            },
            {
              "id": "eee305e9-4164-462a-86bd-80f0d58a31ae",
              "name": "repo_path",
              "type": "string",
              "value": "={{ $vars.repo_path }}"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "73c26f02-1a97-4ebe-af30-85443dd31580",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        -16,
        416
      ],
      "typeVersion": 3.4
    }
  ],
  "pinData": {},
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Get file data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Items",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get File": {
      "main": [
        [
          {
            "node": "Merge Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File is new": {
      "main": [
        [
          {
            "node": "Create new file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Items": {
      "main": [
        [
          {
            "node": "isDiffOrNew",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "isDiffOrNew": {
      "main": [
        [
          {
            "node": "Create sub path",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Status": {
      "main": [
        [
          {
            "node": "Same file - Do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "File is different",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "File is new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get file data": {
      "main": [
        [
          {
            "node": "If file too large",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create new file": {
      "main": [
        [
          {
            "node": "Return",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create sub path": {
      "main": [
        [
          {
            "node": "Check Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File is different": {
      "main": [
        [
          {
            "node": "Edit existing file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If file too large": {
      "main": [
        [
          {
            "node": "Get File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit existing file": {
      "main": [
        [
          {
            "node": "Return",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Same file - Do nothing": {
      "main": [
        [
          {
            "node": "Return",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "8d7e10ce-23ca-4aa4-9b70-a66bfbd4c4e6",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "108ca395ced197c6477117d33be04fdbb054b19068f57471dcf11fcb19567da0"
  },
  "id": "ullZK5zc0t-Q5w-2B_z0n",
  "tags": []
}